package com.njit.springboot.controller;

import com.njit.springboot.bean.RoncooUserLog;
import com.njit.springboot.cache.RoncooUserLogCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping(value = "/ehcache")
public class EhcacheController {

    @Autowired
    private RoncooUserLogCache roncooUserLogCache;

    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public RoncooUserLog get(@RequestParam(defaultValue = "测试") String username) {
        return roncooUserLogCache.selectByUserName(username);
    }
    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public RoncooUserLog update(@RequestParam(defaultValue = "测试") String username) {
        RoncooUserLog bean = roncooUserLogCache.selectByUserName(username);
        bean.setUserName("测试test");
        bean.setCreateTime(new Date());
        roncooUserLogCache.updateByUserName(bean);
        return bean;
    }
    @RequestMapping(value = "/del", method = RequestMethod.GET)
    public String del(@RequestParam(defaultValue = "1") Integer id) {
        return roncooUserLogCache.deleteById(id);
    }
}
